package com.ssy.lingxi.order.model.constant;

import com.ssy.lingxi.common.language.LanguageHolder;

import java.util.Arrays;

/**
 * 订单商品配送方式枚举
 * @author 万宁
 * @version 2.0.0
 * @date 2021-07-15
 */
public enum OrderProductDeliverTypeEnum {
    /**
     * 物流配送 - 1
     */
    LOGISTICS(1, "物流"),

    /**
     * 自提 - 2
     */
    PICK_UP_ADDRESS(2, "自提"),

    /**
     * 无需配送 - 3
     */
    NO_DELIVERY(3, "无需配送"),

    /**
     * 物流+自提 - 4
     */
    LOGISTICS_PICK_UP(4, "物流+自提");

    OrderProductDeliverTypeEnum(java.lang.Integer code, String name) {
        this.code = code;
        this.name = name;
    }

    private Integer code;

    private String name;

    public Integer getCode() {
        return code;
    }

    public String getName() {
        return LanguageHolder.getName(this.getDeclaringClass(), this.getCode());
    }

    /**
     * 根据枚举值获得名称
     * @param code 枚举值
     * @return 配送方式名称
     */
    public static String getNameByCode(Integer code) {
        OrderProductDeliverTypeEnum typeEnum = Arrays.stream(OrderProductDeliverTypeEnum.values()).filter(e -> e.getCode().equals(code)).findFirst().orElse(null);
        return typeEnum == null ? "未知" : typeEnum.getName();
    }
}
